$(function(){
    initTable();
    $.fn.zTree.init($("#treeDemo"), setting);
    $(".pull-right.pagination-detail").css("display","none");
})
var setting = {
    async : {
        enable : true,
        url : "/jxkh/dept/dragtree.json",
        dataType : "json",
        type : 'get',
        autoParam : [ "deptId" ],
        dataFilter : function(treeId, parentNode, childNodes) {
            $.each(childNodes,function(i,node){
                node.drag = true;
            });
            return childNodes.data
        }
    },
    callback : {
        onClick : zTreeOnClick
    },
    data : {
        key:{
            name:"alias"
        },
        simpleData : {
            enable : true,
            idKey : "deptId",
            pIdKey : "parentId",
            rootPId : 0
        }
    },
    edit:{
        enable:true,
        showRemoveBtn:false,
        showRenameBtn:false
    }
};
function zTreeOnClick(event, treeId, treeNode) {
    //$("#deptid").val(treeNode.deptId);
    var opt = {
        url :"/jxkh/task/relation/beCheckerList.json",//考官列表
        silent: true,
        query:{
            deptid:treeNode.deptId,
            checkerdbid:$("#checkerdbid").val()
        }
    };
    $("#boot_table").bootstrapTable('refresh', opt);
}


var $table = $('#boot_table'),
    $remove = $('#remove'),
    selectionIds = [];

function initTable() {
    $('#boot_table').bootstrapTable({
        idField: "dbId",
        sidePagination:'server',
        url: '/jxkh/task/relation/beCheckerList.json',//考官列
        height: getHeight(),
        queryParams:{
            deptid:$("#deptid").val(),
            checkerdbid:$("#checkerdbid").val()
        },
        columns: [
            {
                field: 'checkStatus',
                align: 'center',
                checkbox: true
            }, {
                title: '序号',
                field: 'Number',
                align: 'center',
                formatter: function (value, row, index) {
                    var page = $('#boot_table').bootstrapTable("getOptions");
                    return ((page.pageNumber - 1) * page.pageSize) + index + 1;
                }
            }, {
                title: '姓名',
                field: 'name',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'dutyName',
                title: '职务',
                align: 'center'
            }, {
                title: '职务层次',
                field: 'dutyId',
                align: 'center',
                valign: 'middle'
            }

        ]
    });
}

function getHeight() {
    return $(window).height() - $('h1').outerHeight(true)-73;
}
